package org.zn.mvcbase.validate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;

import deprecated.AbstractExceptionHandler;

/**
 * @ProjectName:webapp_sysmodule
 * @Description: 
 * @Copyright: Copyright (c) 2016

 * @author: 周楠
 * @date 2016年6月13日 上午11:25:43
 */
@Deprecated
public class ValidatedExceptionHandler extends AbstractExceptionHandler <ValidatedException> {



	@Override
	public ModelAndView doHandlerException(HttpServletRequest request, HttpServletResponse response
			, Object handler, Exception exception) {

		ValidatedException ve = (ValidatedException) exception;

		ValidatedResult vr = ve.getVr();
		
		ModelAndView modelview=new ModelAndView();
	
		 ResponseBody responseBodyAnn = AnnotationUtils.findAnnotation(((HandlerMethod)handler).getMethod(), ResponseBody.class);  
		  if (responseBodyAnn != null) {  
			
	
				  HttpOutputMessage outputMessage = new ServletServerHttpResponse(response);  
				  
//				HttpMessageConverter<ResponseMessage> jsonConverter=  (HttpMessageConverter<ResponseMessage>) converterMap.get("jsonConverter");
//						  
//				 jsonConverter.write(vr.getValidatedMessage(), MediaType.APPLICATION_JSON, outputMessage);
				  
			
	        }  else{
	        	
	        	modelview.setViewName(vr.getForwardurl());
	        }
		
	
		return modelview;
	}

}
